package cn.tedu.stx_admin.dao.persist.repository.impl;

import cn.tedu.stx_admin.dao.persist.mapper.AdminMapper;
import cn.tedu.stx_admin.dao.persist.repository.IAdminRepository;

import cn.tedu.stx_admin.pojo.entity.Admin;
import cn.tedu.stx_admin.pojo.vo.AdminLoginInfoVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class AdminRepository implements IAdminRepository {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public int insert(Admin admin) {
        return adminMapper.insert(admin);
    }

    @Override
    public int countByName(String name) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("admin_name",name);
        return adminMapper.selectCount(wrapper);
    }

    public AdminLoginInfoVO getLoginVOByAdminName(String adminName){
        AdminLoginInfoVO loginInfoVO = adminMapper.selectAdminVOByUsername(adminName);
        return loginInfoVO;
    }

    @Override
    public int delete(Long id) {
        QueryWrapper<Admin> wrapper=new QueryWrapper<>();
        wrapper.eq("id",id);
        int result = adminMapper.delete(wrapper);
        return result;
    }


}
